﻿<?php get_header(); ?>
	<section class="content">
		<section class="content_wrapp">
			<h1>Результаты поиска</h1>
				<?php 
					$i = 1;
					$first_box = '<div class="first_line">';
					$second_box = '<div class="second_line">';
					$third_box = '<div class="third_line">';
					if (have_posts()) : while (have_posts()) : the_post();
					$post_categories = '';
					$alpha = true;
					$ccats = get_the_category(get_the_ID());
					if(!empty($ccats)){
						foreach ($ccats as $c){
							if(!$alpha) $post_categories .= ', ';
							$post_categories .= '<a href="'.get_category_link($c->term_id).'">'.$c->cat_name.'</a>';
							$alpha = false;
						}
					}
					$posthtml = '<article class="main_news"><h3>'.get_the_title(get_the_ID()).'</h3><div class="news_middle">
								<span class="news_date">'.get_the_time("m.d.Y", get_the_ID()).'</span>
								<span class="news_autor"><a href="#" title="'.get_the_author().'">'.get_the_author().'</a></span>
								<span class="news_category">'.$post_categories.'</span>';
					if ( has_post_thumbnail() ) {
						$posthtml .= '<a class="border_posts" href="'.get_permalink(get_the_ID()).'" title="'.get_the_title().'">'.get_the_post_thumbnail(get_the_ID(), 'thumb-size-4',
							array('title' => get_the_title())
						).'<span class="left_border"></span><span class="right_border"></span><span class="top_border"></span><span class="bottom_border"></span></a>';
					}
					$posthtml.= '<p>'.get_the_excerpt().'</p></div>
							<div class="news_bottom">
								<span class="news_views">15 просмотров</span>	
								<span class="news_coments"><a href="'.get_permalink(get_the_ID()).'/#comments" title="">'.get_comments_number(get_the_ID()).' комментариев</a></span>	
								<a class="news_more" href="'.get_permalink(get_the_ID()).'" title="Подробнее"><span>Подробнее</span></a>
							</div></article>';
					if($i == 1){
						$first_box .= $posthtml ;
						$posthtml = '';
						$i++;
					} elseif($i == 2){
						$second_box .= $posthtml ;
						$posthtml = '';
						$i++;
					} elseif($i == 3) {
						$third_box .= $posthtml ;
						$posthtml = '';
						$i = 0;
						$i++;
					}
					endwhile;
					$first_box .= '</div>';
					$second_box .= '</div>';
					$third_box .= '</div>';
					echo $first_box.$second_box.$third_box;
					else : echo'<p class="not_found">По Вашему запросу ничего не найдено.</p>';
				endif; ?>
			</section>
			<?php get_sidebar(); ?>
		</section>
	</div>
<?php get_footer(); ?>